home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / scbench.arc / SCDSSK.C < prev    next >
Text File  |  1980-01-01  |  4KB  |  157 lines

  1.  
  2. /*
  3. ** BYTE DOS-level disk seek and read benchmark
  4. ** Version 1 for 8088/8086/80286/80386
  5. ** March 1988
  6. ** Written in BYTE Small-C
  7. ** Based on Small-C by J.E. Hendrix
  8. **
  9. ** Operation:
  10. ** 1. Prompt operator for which disk device to test.
  11. ** 2. Determine maximum number of DOS sectors on device
  12. ** 3. Seek across DOS partition in tenths, reading 1 sector.
  13. ** 4. Report time for (3)
  14. ** 5. Seek across DOS partition in tenths, reading 8 sectors.
  15. ** 6. Report time for (5)
  16. ** 7. Exit 
  17. */
  18. #define COUNT 50    /* # of iterations */
  19. #define stdin 0        /* Standard in */
  20. #define stdout 1    /* Standard out */
  21.  
  22. char *buff;        /* Buffer for sectors */
  23. int tblock[4];        /* Timer block */
  24. int ddblock[4];        /* DOS disk information block */
  25. int drive;        /* Drive designation
  26. int sect;        /* Sector size
  27. int accum;        /* Time accumulator
  28. int tsects;        /* Total # of sectors */
  29. int ssize;        /* Step size */
  30. int i,j;        /* For loops */
  31.  
  32. main()
  33. {
  34.  
  35. /* Announce program and determine drive to use */
  36.     printf("BYTE DOS Disk Seek-And-Read Benchmark\n");
  37.     printf("(Times reported are in 1/100ths of a second\n");
  38.     printf("Which drive (1=A, 2=B ...)?");
  39.     fscanf(stdin,"%d",&drive);
  40.  
  41. /* Get information on selected drive */
  42.     ddblock[0]=drive;     /*Load drive info to send to gddinfo*/
  43.     gddinfo(ddblock);
  44.     tsects=ddblock[3]*ddblock[0];    /* Total Clusters * Clusters/Sector */
  45.     printf("Total sectors for this disk:%u\n",tsects);
  46.  
  47. /* Allocate memory for up to 8 sectors */
  48.     buff=malloc(ddblock[2]*8);
  49.  
  50. /* First test...read across the disk in tenths reading 1 sector */
  51. /* Assembler routine does an unsigned divide (tsects/10) to determine*/
  52. /* step size (ssize)  */
  53. #asm
  54.     MOV    AX,_tsects
  55.     XOR    DX,DX
  56.     MOV    BX,10
  57.     DIV    BX
  58.     MOV    _ssize,AX
  59. #endasm
  60.     accum=0;        /* Initialize time counter */
  61.     for(i=0;i<COUNT;++i)    /* Perform test COUNT times*/
  62.     {
  63.         ddseek(drive,0,1,buff);    /* Start at 0 */
  64.         sect=0;
  65.         for(j=0;j<10;++j)    /*Step through 10 steps */
  66.         {
  67.             sect+=ssize;
  68.             gtime(tblock);    /* Start timer */
  69.             ddseek(drive,sect,1,buff);
  70.             calctim(tblock);    /* Stop timer */
  71.             accum+=tblock[3]+100*(tblock[2]+
  72.                 60*tblock[1]);    /*Increment time counter */
  73.         }
  74.     }
  75.     printf("Step 10th of total/ Read 1 sector\n");
  76.     printf("# of Seeks Timed:%d\n",COUNT*10);
  77.     printf("Total time:%d\n",accum);
  78.  
  79. /* Second test... Same as first test except data is read in eight sector
  80. ** blocks */
  81.     accum=0;
  82.     for(i=0;i<COUNT;++i)
  83.     {
  84.         ddseek(drive,0,1,buff);    /* Start at 0 */
  85.         sect=0;
  86.         for(j=0;j<10;++j)
  87.         {
  88.             sect+=ssize;
  89.             /* Don't fall off the end */
  90.             if(sect>(tsects-8)) sect=tsects-8;
  91.             gtime(tblock);
  92.             ddseek(drive,sect,8,buff);  /* Read eight sectors */
  93.             calctim(tblock);
  94.             accum+=tblock[3]+100*(tblock[2]+
  95.                 60*tblock[1]);
  96.         }
  97.     }
  98.     printf("Step 10th of total/ Read 8 sectors\n");
  99.     printf("# of Seeks Timed:%d\n",COUNT*10);
  100.     printf("Total time:%d\n",accum);
  101.  
  102.  
  103.  
  104. /* Exit */
  105.     exit(0);
  106. }
  107.  
  108. /*
  109. **
  110. ** gddinfo(ddblock) - Get DOS disk info
  111. ** ddblock is a 4-element array
  112. ** Entry: ddblock[0] holds drive # (0=A, 1=B...)
  113. ** Exit: ddblock[0] = sectors/cluster
  114. **       ddblock[1] = available clusters
  115. **       ddblock[2] = bytes per sector
  116. **       ddblock[3] = total clusters
  117. */
  118. gddinfo(ddblock) int ddblock[];
  119. {
  120. #asm
  121.     MOV    BP,SP
  122.     MOV    SI,2[BP]    ;Pointer to ddblock[0]
  123.     MOV    DL,[SI]        ;Drive #
  124.     MOV    AH,36H        ;Function #
  125.     PUSH    SI        ;Save just in case
  126.     INT    21H        ;Get disk info
  127.     POP    SI        ;Recover ddblock pointer
  128.     MOV    [SI],AX        ;Sectors/cluster
  129.     MOV    2[SI],BX    ;Avail clusters
  130.     MOV    4[SI],CX    ;Bytes/sector
  131.     MOV    6[SI],DX    ;Total clusters
  132.     XOR    CX,CX        ;For Small-C
  133. #endasm
  134. }
  135.  
  136. /*
  137. **
  138. ** ddseek(drive,sector,num,buff) int drive,sector,num; char *buff;
  139. ** DOS disk seek to sector on drive.  Read in num sectors into buff.
  140. ** NOTE: This routine decrements drive so that 0=A, 1=B..etc.
  141. ** 
  142. */
  143. ddseek(drive,sector,num,buff) int drive,sector,num;
  144. char *buff;
  145. {
  146. #asm
  147.     MOV    BP,SP
  148.     MOV    AL,8[BP]    ;Get drive
  149.     DEC    AL        ;Decrement so in interrupt format
  150.     MOV    DX,6[BP]    ;Get sector #
  151.     MOV    CX,4[BP]    ;Number of sectors
  152.     MOV    BX,2[BP]    ;Buffer address
  153.     INT    25H        ;Read
  154.     POP    DX        ;Dump the extra word
  155.     XOR    CX,CX        ;For Small-C
  156. #endasm
  157. }